package day17;

public class Demo {
    public static void main(String[] args) {
        Thread vip=new Thread(()->{
            String name=Thread.currentThread().getName();
            for (int i=1;i<=10;i++){
                if (i==1) Thread.yield();
                System.out.println("第"+i+"个"+name+"在看病!");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"vip用户");
        Thread user=new Thread(()->{
            String name=Thread.currentThread().getName();
            for (int i=1;i<=50;i++){
                System.out.println("第"+i+"个"+name+"在看病!");
                try {
                    Thread.sleep(500);
                    //当普通用户看完10个后，优先vip用户看完，再看普通用户
                    if (i==10) vip.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"普通用户");
        //设置优先级
        vip.setPriority(Thread.MAX_PRIORITY);  //10
        user.setPriority(Thread.MIN_PRIORITY); //1

        vip.start();
        user.start();
    }
}
